home *** CD-ROM | disk | FTP | other *** search
Wrap
CCCCOOOOMMMMPPPP((((2222)))) CCCCOOOOMMMMPPPP((((2222)))) NNNNAAAAMMMMEEEE comp,uncomp,comp_compress,uncomp_uncompress - data stream compression and uncompression CCCC SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS ####iiiinnnncccclllluuuuddddeeee <<<<ccccoooommmmpppp....hhhh>>>> ttttyyyyppppeeeeddddeeeeffff vvvvooooiiiidddd ****((((****ccccoooommmmpppp____aaaallllllllooooccccaaaattttoooorrrr____tttt))))((((ssssiiiizzzzeeee____tttt))));;;; ttttyyyyppppeeeeddddeeeeffff vvvvooooiiiidddd ((((****ccccoooommmmpppp____ffffrrrreeeeeeee____tttt))))((((vvvvooooiiiidddd ****))));;;; ttttyyyyppppeeeeddddeeeeffff ssssssssiiiizzzzeeee____tttt ((((****ccccoooommmmpppp____oooouuuuttttppppuuuutttt____tttt))))((((vvvvooooiiiidddd ****ppppaaaarrrraaaammmm,,,, vvvvooooiiiidddd ****bbbbuuuuffff,,,, ssssiiiizzzzeeee____tttt bbbbuuuufffflllleeeennnn))));;;; vvvvooooiiiidddd ccccoooommmmpppp____ooooppppttttiiiioooonnnnssss____ddddeeeeffffaaaauuuulllltttt((((CCCCOOOOMMMMPPPP____OOOOPPPPTTTTIIIIOOOONNNNSSSS ****))));;;; vvvvooooiiiidddd ccccoooommmmpppp____iiiinnnniiiitttt((((CCCCOOOOMMMMPPPP____DDDDAAAATTTTAAAA ****,,,, ccccoooommmmpppp____aaaallllllllooooccccaaaattttoooorrrr____tttt,,,, ccccoooommmmpppp____ffffrrrreeeeeeee____tttt,,,, ccccoooommmmpppp____oooouuuuttttppppuuuutttt____tttt))));;;; iiiinnnntttt ccccoooommmmpppp____bbbbeeeeggggiiiinnnn((((CCCCOOOOMMMMPPPP____DDDDAAAATTTTAAAA ****,,,, CCCCOOOOMMMMPPPP____OOOOPPPPTTTTIIIIOOOONNNNSSSS ****))));;;; iiiinnnntttt ccccoooommmmpppp____ccccoooommmmpppprrrreeeessssssss((((CCCCOOOOMMMMPPPP____DDDDAAAATTTTAAAA ****,,,, ccccoooonnnnsssstttt cccchhhhaaaarrrr____ttttyyyyppppeeee ****bbbbuuuuffff,,,, lllloooonnnngggg bbbbuuuufffflllleeeennnn))));;;; iiiinnnntttt ccccoooommmmpppp____eeeennnndddd((((CCCCOOOOMMMMPPPP____DDDDAAAATTTTAAAA ****))));;;; vvvvooooiiiidddd ccccoooommmmpppp____ddddeeeessssttttrrrrooooyyyy((((CCCCOOOOMMMMPPPP____DDDDAAAATTTTAAAA ****))));;;; iiiinnnntttt ccccoooommmmpppp____ggggeeeetttteeeerrrrrrrrnnnnoooo((((CCCCOOOOMMMMPPPP____DDDDAAAATTTTAAAA ****))));;;; vvvvooooiiiidddd ccccoooommmmpppp____ccccllllrrrreeeerrrrrrrrnnnnoooo((((UUUUNNNNCCCCOOOOMMMMPPPP____DDDDAAAATTTTAAAA ****))));;;; ####iiiinnnncccclllluuuuddddeeee <<<<uuuunnnnccccoooommmmpppp....hhhh>>>> ttttyyyyppppeeeeddddeeeeffff vvvvooooiiiidddd ****((((****uuuunnnnccccoooommmmpppp____aaaallllllllooooccccaaaattttoooorrrr____tttt))))((((ssssiiiizzzzeeee____tttt))));;;; ttttyyyyppppeeeeddddeeeeffff vvvvooooiiiidddd ((((****uuuunnnnccccoooommmmpppp____ffffrrrreeeeeeee____tttt))))((((vvvvooooiiiidddd ****))));;;; ttttyyyyppppeeeeddddeeeeffff ssssssssiiiizzzzeeee____tttt ((((****uuuunnnnccccoooommmmpppp____oooouuuuttttppppuuuutttt____tttt))))((((vvvvooooiiiidddd ****ppppaaaarrrraaaammmm,,,, vvvvooooiiiidddd ****bbbbuuuuffff,,,, ssssiiiizzzzeeee____tttt bbbbuuuufffflllleeeennnn))));;;; vvvvooooiiiidddd uuuunnnnccccoooommmmpppp____ooooppppttttiiiioooonnnnssss____ddddeeeeffffaaaauuuulllltttt((((UUUUNNNNCCCCOOOOMMMMPPPP____OOOOPPPPTTTTIIIIOOOONNNNSSSS ****))));;;; iiiinnnntttt uuuunnnnccccoooommmmpppp____iiiinnnniiiitttt((((UUUUNNNNCCCCOOOOMMMMPPPP____DDDDAAAATTTTAAAA ****,,,, uuuunnnnccccoooommmmpppp____aaaallllllllooooccccaaaattttoooorrrr____tttt,,,, uuuunnnnccccoooommmmpppp____ffffrrrreeeeeeee____tttt,,,, uuuunnnnccccoooommmmpppp____oooouuuuttttppppuuuutttt____tttt))));;;; iiiinnnntttt uuuunnnnccccoooommmmpppp____bbbbeeeeggggiiiinnnn((((UUUUNNNNCCCCOOOOMMMMPPPP____DDDDAAAATTTTAAAA ****,,,, UUUUNNNNCCCCOOOOMMMMPPPP____OOOOPPPPTTTTIIIIOOOONNNNSSSS ****))));;;; iiiinnnntttt uuuunnnnccccoooommmmpppp____uuuunnnnccccoooommmmpppprrrreeeessssssss((((UUUUNNNNCCCCOOOOMMMMPPPP____DDDDAAAATTTTAAAA ****,,,, ccccoooonnnnsssstttt cccchhhhaaaarrrr____ttttyyyyppppeeee ****bbbbuuuuffff,,,, lllloooonnnngggg bbbbuuuufffflllleeeennnn))));;;; iiiinnnntttt uuuunnnnccccoooommmmpppp____eeeennnndddd((((UUUUNNNNCCCCOOOOMMMMPPPP____DDDDAAAATTTTAAAA ****))));;;; PPPPaaaaggggeeee 1111 CCCCOOOOMMMMPPPP((((2222)))) CCCCOOOOMMMMPPPP((((2222)))) vvvvooooiiiidddd uuuunnnnccccoooommmmpppp____ddddeeeessssttttrrrrooooyyyy((((UUUUNNNNCCCCOOOOMMMMPPPP____DDDDAAAATTTTAAAA ****))));;;; iiiinnnntttt uuuunnnnccccoooommmmpppp____ggggeeeetttteeeerrrrrrrrnnnnoooo((((UUUUNNNNCCCCOOOOMMMMPPPP____DDDDAAAATTTTAAAA ****))));;;; vvvvooooiiiidddd uuuunnnnccccoooommmmpppp____ccccllllrrrreeeerrrrrrrrnnnnoooo((((UUUUNNNNCCCCOOOOMMMMPPPP____DDDDAAAATTTTAAAA ****))));;;; OOOOVVVVEEEERRRRVVVVIIIIEEEEWWWW The _c_o_m_p library and associated system calls allows applications to use the compression and decompression algorithms from _c_o_m_p_r_e_s_s(1) and _u_n_c_o_m_p_r_e_s_s(1) directly, without having to invoke a separate executable. The compression code in this library has been optimized, and if used in combination with large buffer file reading can result in improved compression times of up to 30% over the standard compress code. You must link with the _cccc_oooo_mmmm_pppp _l_i_b_r_a_r_y: cc -o prog prog.c -lcomp DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN Applications wishing to compress data should: 1 include _c_o_m_p._h header file 2 define an instance of a _C_O_M_P__D_A_T_A stream (let's call it _xxxx_xxxx_xxxx) 3 define memory allocator method: _v_o_i_d *_x_x_x_m_a_l_l_o_c(_s_i_z_e__t) 4 define corresponding memory free method: _v_o_i_d _x_x_x_f_r_e_e(_b_u_f) 5 define output handler method: _s_s_i_z_e__t _x_x_x_o_u_t_p_u_t(_p_a_r_a_m, _o_u_t_b_u_f, _o_u_t_b_u_f_l_e_n) 6 define an instance of COMP_OPTIONS options structure: _xxxx_xxxx_xxxx_oooo_pppp_tttt_ssss 7 invoke _c_o_m_p__o_p_t_i_o_n_s__d_e_f_a_u_l_t(&_x_x_x_o_p_t_s) to set default options 8 invoke _c_o_m_p__i_n_i_t(&_x_x_x, &_x_x_x_m_a_l_l_o_c, &_x_x_x_f_r_e_e, &_x_x_x_o_u_t_p_u_t) 9 explicitly set any non-default options desired in _xxxx_xxxx_xxxx_oooo_pppp_tttt_ssss, especially _xxxx_xxxx_xxxx_oooo_pppp_tttt_ssss_...._oooo_uuuu_tttt_pppp_uuuu_tttt______pppp_aaaa_rrrr_aaaa_mmmm, which is passed to _x_x_x_o_u_t_p_u_t() 10 invoke _c_o_m_p__b_e_g_i_n(&_x_x_x, &_x_x_x_o_p_t_s) 11 invoke _c_o_m_p__c_o_m_p_r_e_s_s(&_x_x_x, _i_n_b_u_f, _i_n_b_u_f_l_e_n) 12 invoke _c_o_m_p__e_n_d(&_x_x_x) PPPPaaaaggggeeee 2222 CCCCOOOOMMMMPPPP((((2222)))) CCCCOOOOMMMMPPPP((((2222)))) 13 repeat steps (9) through (12) as necessary, for each file to be compressed. 14 it is okay to reuse compress structs for other compressed streams, by invoking _c_o_m_p__b_e_g_i_n() on them again. 15 invoke _c_o_m_p__d_e_s_t_r_o_y(&_x_x_x) to free up allocated memory Expect during above: 1 calls to _x_x_x_m_a_l_l_o_c() during _c_o_m_p__b_e_g_i_n() for space that the compressor might need 2 calls to _x_x_x_o_u_t_p_u_t() during _c_o_m_p__c_o_m_p_r_e_s_s() and _c_o_m_p__e_n_d(), to emit compressed results. 3 calls to _x_x_x_f_r_e_e() during _c_o_m_p__d_e_s_t_r_o_y() and _c_o_m_p__b_e_g_i_n(). To uncompress data: 1 include _u_n_c_o_m_p._h header file 2 define an instance of a _U_N_C_O_M_P__D_A_T_A stream (let's call it _xxxx_xxxx_xxxx) 3 define memory allocator method: _v_o_i_d *_x_x_x_m_a_l_l_o_c(_s_i_z_e__t) 4 define corresponding memory free method: _v_o_i_d _x_x_x_f_r_e_e(_b_u_f) 5 define output handler method: _s_s_i_z_e__t _x_x_x_o_u_t_p_u_t(_p_a_r_a_m, _o_u_t_b_u_f, _o_u_t_b_u_f_l_e_n) 6 define an instance of UNCOMP_OPTIONS options structure: _xxxx_xxxx_xxxx_oooo_pppp_tttt_ssss 7 invoke _u_n_c_o_m_p__o_p_t_i_o_n_s__d_e_f_a_u_l_t(&_x_x_x_o_p_t_s) to set default options 8 invoke _u_n_c_o_m_p__i_n_i_t(&_x_x_x, &_x_x_x_m_a_l_l_o_c, &_x_x_x_f_r_e_e, &_x_x_x_o_u_t_p_u_t) 9 explicitly set any non-default options desired in _xxxx_xxxx_xxxx_oooo_pppp_tttt_ssss, especially _xxxx_xxxx_xxxx_oooo_pppp_tttt_ssss_...._oooo_uuuu_tttt_pppp_uuuu_tttt______pppp_aaaa_rrrr_aaaa_mmmm, which is passed to _x_x_x_o_u_t_p_u_t() 10 invoke _u_n_c_o_m_p__b_e_g_i_n(&_x_x_x, &_x_x_x_o_p_t_s) 11 invoke _u_n_c_o_m_p__u_n_c_o_m_p_r_e_s_s(&_x_x_x, _i_n_b_u_f, _i_n_b_u_f_l_e_n) 12 invoke _u_n_c_o_m_p__e_n_d(&_x_x_x) 13 repeat steps (9) through (12) as necessary, for each file to be compressed. PPPPaaaaggggeeee 3333 CCCCOOOOMMMMPPPP((((2222)))) CCCCOOOOMMMMPPPP((((2222)))) 14 it is okay to reuse uncompress structs for other compressed streams, by invoking _u_n_c_o_m_p__b_e_g_i_n() on them again. 15 invoke _u_n_c_o_m_p__d_e_s_t_r_o_y(&_x_x_x) to free up allocated memory Expect during above: 1 calls to _x_x_x_m_a_l_l_o_c() during _u_n_c_o_m_p__i_n_i_t() for space that the uncompressor might need 2 calls to _x_x_x_o_u_t_p_u_t() during _u_n_c_o_m_p__u_n_c_o_m_p_r_e_s_s() and _u_n_c_o_m_p__e_n_d(), to emit uncompressed results. 3 calls to _x_x_x_f_r_e_e() during _u_n_c_o_m_p__d_e_s_t_r_o_y() and _u_n_c_o_m_p__b_e_g_i_n().. SSSSEEEEEEEE AAAALLLLSSSSOOOO compress(1), uncompress(1) DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS All routines that return a status value return 0 for success, -1 for failure. _c_o_m_p__e_n_d and _u_n_c_o_m_p__e_n_d can also return -2 if no gain was had by compressing the stream. PPPPaaaaggggeeee 4444